library ShowStatsCommand initializer init requires LegacySystem

	private function MyMedals takes nothing returns boolean
		local string s = SubString(GetEventPlayerChatString(),0,StringLength(GetEventPlayerChatString()))
		local integer i = 1
		local player p = GetTriggerPlayer()
		local player displayplayer = p
		local integer j = GetConvertedPlayerId(p)

		//local integer mos = GetStoredInteger(udg_MedalCache,I2S(j),"11")
		
		local integer mos = 0
		local integer CR = 0
		
		set mos = GetI("player mos", GetConvertedPlayerId(p))
		set CR =  GetPlayerTechCount(p, 'R015', true) * 4 + 72
		
		if s=="-showstats" then
			call DisplayTimedTextToPlayer(GetLocalPlayer() , 0, 0, 20.0, " " )
			call DisplayTimedTextToPlayer(GetLocalPlayer() , 0, 0, 20.0, "|cfff3ad00Statistics|r - " + udg_Pcolors[j] + GetPlayerName(p) + "|r" )
			call DisplayTimedTextToPlayer(GetLocalPlayer() ,0,0, 20.0, "Combat Readiness : " + I2S(CR)+ "%")
			call DisplayTimedTextToPlayer(GetLocalPlayer() ,0,0, 20.0, "Specialization : "+udg_MOSText[mos] )
			loop
				exitwhen i>13
				if i==11 then
					set i=13 //DI Ribbon
				endif
				
				if GetPlayerTechCount(p, udg_Medal[i], true) > 0 then
					call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0, 20.0, "|cff3399ff" + udg_MedalName[i] + "|r" )
				else
					call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0, 20.0, "|cff696969" + udg_MedalName[i] + "|r" )
				endif
				
				set i=i+1
			endloop
			call DisplayTimedTextToPlayer(GetLocalPlayer() , 0.0, 0.0, 20.0, " " )
			call DisplayTimedTextToPlayer(GetLocalPlayer() , 0.0, 0.0, 20.0, " " )
		elseif s=="-stats" then

			call DisplayTimedTextToPlayer(p, 0, 0, 20.0, " " )
			call DisplayTimedTextToPlayer(p, 0, 0, 20.0, "|cfff3ad00Statistics|r - " + udg_Pcolors[j] + GetPlayerName(p) + "|r" )
			call DisplayTimedTextToPlayer(p ,0,0, 20.0, "Combat Readiness : " + I2S(CR)+ "%")
			call DisplayTimedTextToPlayer(p,0,0, 20.0, "Specialization : "+udg_MOSText[mos] )
			loop
				exitwhen i>13
				if i==11 then
					set i=13 //DI Ribbon
				endif
				
				if GetPlayerTechCount(p, udg_Medal[i], true) > 0 then
					call DisplayTimedTextToPlayer(p,0,0, 20.0, "|cff3399ff" + udg_MedalName[i] + "|r" )
				else
					call DisplayTimedTextToPlayer(p,0,0, 20.0, "|cff696969" + udg_MedalName[i] + "|r" )
				endif

				set i=i+1
			endloop
			call DisplayTimedTextToPlayer(p, 0.0, 0.0, 20.0, " " )
			call DisplayTimedTextToPlayer(p, 0.0, 0.0, 20.0, " " )
		endif
		
		set p = null
		return false
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		local integer i = 0
		set t = CreateTrigger()
		loop
			exitwhen i > 11
			call TriggerRegisterPlayerChatEvent(t, Player(i), "-showstats", true)
			call TriggerRegisterPlayerChatEvent(t, Player(i), "-stats", true)
			set i = i + 1
		endloop
		call TriggerAddCondition(t, Condition(function MyMedals))
	endfunction
endlibrary

